#include <QFile>
#include "ResourceController.h"
#include "DefaultResource.h"
#include "CustomResource.h"

static const QString CustomFileName = "CustomSetting.dat";

ResourceController* ResourceController::m_inst = NULL;

ResourceController::ResourceController()
    : m_resource(NULL)
{
    QFile file(CustomFileName);
    if (!file.open(QFile::ReadOnly)) {
        m_resource = new DefaultResource();
    }
    else {
        m_resource = new CustomResource(file);
        file.close();
    }
}

ResourceController* ResourceController::inst()
{
    if (NULL == m_inst) {
        m_inst = new ResourceController();
    }

    return m_inst;
}

float ResourceController::getStartMoney()
{
    if (NULL != m_resource) {
        return m_resource->getStartMoney();
    }

    return 0.0f;
}

QMap<IncomeItem,QString> ResourceController::getIncomingItem()
{
    if (NULL != m_resource) {
        return m_resource->getIncomingItem();
    }

    return QMap<IncomeItem,QString>();
}

QMap<OutgointItem,QString> ResourceController::getOutgointItem()
{
    if (NULL != m_resource) {
        return m_resource->getOutgointItem();
    }

    return QMap<OutgointItem,QString>();
}

RateTable ResourceController::calculateRate(float money){
    if (NULL != m_resource) {
        return m_resource->calculateRate(money);
    }
    return RateTable();
}
